package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseRealWarehouse;
import com.sumi.erp.service.IBaseRealWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实体仓库Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/erp/real/warehouse")
public class BaseRealWarehouseController extends BaseController
{
    @Autowired
    private IBaseRealWarehouseService baseRealWarehouseService;

    /**
     * 查询实体仓库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseRealWarehouse baseRealWarehouse)
    {
        startPage();
        List<BaseRealWarehouse> list = baseRealWarehouseService.selectBaseRealWarehouseList(baseRealWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出实体仓库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:export')")
    @Log(title = "实体仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseRealWarehouse baseRealWarehouse)
    {
        List<BaseRealWarehouse> list = baseRealWarehouseService.selectBaseRealWarehouseList(baseRealWarehouse);
        ExcelUtil<BaseRealWarehouse> util = new ExcelUtil<BaseRealWarehouse>(BaseRealWarehouse.class);
        util.exportExcel(response, list, "实体仓库数据");
    }

    /**
     * 获取实体仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseRealWarehouseService.selectBaseRealWarehouseById(id));
    }

    /**
     * 新增实体仓库
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:add')")
    @Log(title = "实体仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseRealWarehouse baseRealWarehouse)
    {
        return toAjax(baseRealWarehouseService.insertBaseRealWarehouse(baseRealWarehouse));
    }

    /**
     * 修改实体仓库
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:edit')")
    @Log(title = "实体仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseRealWarehouse baseRealWarehouse)
    {
        return toAjax(baseRealWarehouseService.updateBaseRealWarehouse(baseRealWarehouse));
    }

    /**
     * 删除实体仓库
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:remove')")
    @Log(title = "实体仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseRealWarehouseService.deleteBaseRealWarehouseByIds(ids));
    }
}
